package com.zzh.ideas.web.filter;

import com.zzh.ideas.web.wrapper.RequestWrapper;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * description: <br>
 * createTime: 2018/7/3014:46 <br>
 *
 * @author zzh
 */
@WebFilter(urlPatterns = "*", filterName = "ProxyFilter")
public class MyFilter implements Filter {

    public static Map<String, String> resourcesUrlMap = new ConcurrentHashMap<>();

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }


    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        // 请求包装，包装的请求构造中，对session进行包装
        System.out.println(request.getRequestURI() + " : " + request.getMethod());
        filterChain.doFilter(new RequestWrapper(request), servletResponse);
    }


    @Override
    public void destroy() {

    }
}
